// import moment from 'moment'

const moment = require('moment');

const buildingStatusList = [
  {
    title: '未开始',
    // color: '#FEB151',
    color: [254, 177, 81, 1],
  },
  {
    title: '未开始(延期)',
    // color: '#FE6751',
    color: [254, 103, 81, 1],
  },
  {
    title: '执行中',
    // color: '#2FB0FF',
    color: [61, 251, 255, 1],
  },
  {
    title: '执行中(延期)',
    // color: '#3D98FF',
    color: [61, 152, 255, 1],
  },
  {
    title: '已完成',
    color: [61, 255, 159, 1],
  },
  {
    title: '已完成（提前）',
    color: [158, 255, 61, 1],
  },
  {
    title: '已完成（延期）',
    color: [232, 61, 255, 1],
  },
];

export let buildingStatusTable = buildingStatusList.reduce(
  (r, e) => {
    r[e.title] = e.color;
    return r;
  },
  { default: buildingStatusList[0].color },
);

var lessData = [
  {
    planId: 1297377660257251329,
    wbs: 'C2-167-3-4',
    // wbs: 'C2-167-3-4',
    parent: '0',
    text: '访仙桥（K0+078.000）0#台基础及下部构造钻孔灌注桩',
    duration: 30,
    startDate: '2020-08-25 00:00:00',
    endDate: '2020-09-24 00:00:00',
    actualDuration: 0,
    actualStartDate: '2020-08-26 00:00:00',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 12251329,
    wbs: 'C2-167-7-3',
    parent: '0',
    text: '路面111',
    duration: 30,
    startDate: '2020-08-25 00:00:00',
    endDate: '2020-09-24 00:00:00',
    actualDuration: 0,
    actualStartDate: '2020-08-26 00:00:00',
    actualEndDate: '2020-09-23 00:00:00',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 12251329,
    wbs: 'C2-167-3-29',
    parent: '0',
    text: '路面111',
    duration: 30,
    startDate: '2020-08-25 00:00:00',
    endDate: '2020-09-24 00:00:00',
    actualDuration: 0,
    actualStartDate: '2020-08-26 00:00:00',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 12251329,
    wbs: 'C2-167-3-33',
    parent: '0',
    text: '路面111',
    duration: 30,
    startDate: '2020-08-25 00:00:00',
    endDate: '2020-09-24 00:00:00',
    actualDuration: 0,
    actualStartDate: '2020-09-01 00:00:00',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 12251329,
    wbs: 'c2-167-3-17',
    parent: '0',
    text: '路面111',
    duration: 30,
    startDate: '2020-08-25 00:00:00',
    endDate: '2020-08-28 00:00:00',
    actualDuration: 0,
    actualStartDate: '2020-08-26 00:00:00',
    actualEndDate: '2020-08-29 00:00:00',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 12251329,
    wbs: 'c2-167-3-18',
    parent: '0',
    text: '路面111',
    duration: 30,
    startDate: '2020-08-25 00:00:00',
    endDate: '2020-08-28 00:00:00',
    actualDuration: 0,
    actualStartDate: '2020-08-26 00:00:00',
    actualEndDate: '2020-08-27 00:00:00',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 1297377660257251329,
    wbs: 'C1-1-11',
    parent: '0',
    text: '访仙桥（K0+078.000）0#台基础及下部构造台背填土',
    duration: 21,
    startDate: '2020-10-22 00:00:00',
    endDate: '2020-11-12 00:00:00',
    actualDuration: 0,
    actualStartDate: '',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 1297377660257251329,
    wbs: 'C1-1-3',
    parent: '0',
    text: '访仙桥（K0+078.000）0#台基础及下部构造桥台',
    duration: 12,
    startDate: '2020-09-25 00:00:00',
    endDate: '2020-10-07 00:00:00',
    actualDuration: 0,
    actualStartDate: '',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 1297377660257251329,
    wbs: 'C1-1-5',
    parent: '0',
    text: '访仙桥（K0+078.000）0#台基础及下部构造台身',
    duration: 15,
    startDate: '2020-10-07 00:00:00',
    endDate: '2020-10-22 00:00:00',
    actualDuration: 0,
    actualStartDate: '',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 1297377660257251329,
    wbs: 'C1-1-7',
    parent: '0',
    text: '访仙桥（K0+078.000）0#台基础及下部构造台帽',
    duration: 15,
    startDate: '2020-10-22 00:00:00',
    endDate: '2020-11-06 00:00:00',
    actualDuration: 0,
    actualStartDate: '',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
  {
    planId: 1297377660257251329,
    wbs: 'C1-1-9',
    parent: '0',
    text: '访仙桥（K0+078.000）0#台基础及下部构造支座垫石和挡块',
    duration: 5,
    startDate: '2020-11-06 00:00:00',
    endDate: '2020-11-11 00:00:00',
    actualDuration: 0,
    actualStartDate: '',
    actualEndDate: '',
    finishSituation: '',
    delaySituation: '',
    projectId: 1296256020068786178,
  },
];

// export default data;

function getDataForUniqValueRender(data, _curDate) {
  let curDate = _curDate ? moment(_curDate) : moment(moment.now());
  let curDateStr = curDate.format('YYYY-MM-DD hh:mm:ss');
  return data.map(({ startDate, endDate, actualStartDate, actualEndDate, wbs }) => {
    let result = { ...buildingStatusList[0], wbs };
    try {
      if (startDate > curDateStr && !actualEndDate) {
        // console.log();
        return result;
      }

      if (actualEndDate) {
        // '已完成'
        if (curDateStr > actualEndDate) {
          result = { ...buildingStatusList[4], wbs };
          // '已完成（提前）'
          if (endDate > actualEndDate) {
            result = { ...buildingStatusList[5], wbs };
          } else if (actualEndDate > endDate) {
            result = { ...buildingStatusList[6], wbs };
          }
        }
      } else if (actualStartDate) {
        // '未开始(延期)'
        if (curDateStr > startDate && actualStartDate > curDateStr) {
          result = { ...buildingStatusList[1], wbs };
        }

        // '执行中'
        if (curDateStr >= actualStartDate && endDate > curDateStr) {
          result = { ...buildingStatusList[2], wbs };
        }

        // '执行中(延期)'
        if (curDateStr > endDate) {
          result = { ...buildingStatusList[3], wbs };
        }
      }

      return result;
    } catch (error) {
      console.warn('判断时间出错', error);
      return result;
    }
  });
  // return data.map(({ startDate, endDate }) => {
  //   console.log(startDate, curDateStr, endDate, startDate > curDateStr, curDateStr > endDate);
  //   return [startDate > curDateStr, curDateStr > endDate];
  // });
}

// console.time('count');
// // console.log(getDataForUniqValueRender(data));
// console.timeEnd('count');

export default () => {
  return getDataForUniqValueRender(lessData);
  // return getDataForUniqValueRender(data);
};
